<?php
error_reporting(0);
require_once("includes/pagetop.php");

if(!isset($_SESSION['Allyfolio_User_ID']) || $_SESSION['Allyfolio_User_ID']==0)
{
    redirect("index.php");
}

$patharr=explode("/",$_SERVER["REQUEST_URI"]);

$lastvars=end($patharr);

$afterWampToProjectRootPath=str_replace($lastvars,"",$_SERVER["REQUEST_URI"]);
if(!(isset($_REQUEST['t']) && trim($_REQUEST['t'])!=''))
{
    redirect("home.php");
}

$dnauserqry="select * from af_users where Allyfolio_User_ID=:afuserid  ";
$condition[":afuserid"]=$_REQUEST['t'];
$dnauserinfo=$pdodbobj->fetch_array($pdodbobj->query($dnauserqry,$condition));

if(count($dnauserinfo)==0)
{
    redirect($_SERVER["HTTP_REFERER"]);
}

//echo "<pre>";
//print_r($dnauserinfo);
//echo "</pre>";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<title>AllyFolio | DNA </title>

<link href="css/style.css" rel="stylesheet" type="text/css" media="all"  />

<script src="js/general.js"></script>

<script src="js/functions.js"></script>

<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>


<link rel="stylesheet" href="bin/magicsuggest-1.3.1-min.css"/>
<script type="text/javascript" src="bin/jquery-1.8.3-min.js"></script>
<script type="text/javascript" src="bin/magicsuggest-1.3.1-min.js"></script>

<link rel="stylesheet" href="alertify/themes/alertify.core.css" />
<link rel="stylesheet" href="alertify/themes/alertify.default.css" id="toggleCSS" />
<script src="alertify/lib/alertify.min.js"></script>	
<script src="js/jquery1.10.2.min.js"></script>
<script src="js/modernizr.custom.56223.js"></script>

<script src="js/jquery.placeholder.js"></script>
<!-- For sharing popup -->
<script type="text/javascript" src="js/script.js"></script>

<style type="text/css">

	.logo{ margin-top:10px;}

	.log_button{

	height:auto;

	margin:6px 0;

	overflow:hidden;

	float:left;

	margin-top:10px;

	}

	.new tr td{ vertical-align:top}

	textarea select{ border:1px solid #ccc}

	input textarea select{ border:1px solid #999}

	

</style>

</head>

<body>
	<div id="main_wrapper">

    <!--=================Header Start=======================-->

	<div class="wrapper row1">
    
    <?php
    require_once("includes/dnaheader.php");
   
    $condition=array();
    $eventsquery="select Event_ID,Event_Name,Event_Place,Event_Date,Event_status,Created_By from af_events where Created_By=:addedby order by Event_Date desc ";
    $condition[":addedby"]=$dnauserinfo[0]['User_ID'];
    
    $eventsinfo=$pdodbobj->fetch_array($pdodbobj->query($eventsquery,$condition));
    
    $condition=array();
    
    $joinedPages=" select * from af_company_page_members as cpm left join af_company_page as cp on cpm.comp_page_id=cp.Comp_Page_ID where cpm.user_id=:user_id and cp.Comp_Type_ID = 18 and cp.Status=0";
    $condition[":user_id"]=$dnauserinfo[0]['User_ID'];
    $joinedPagesInfo=$pdodbobj->fetch_array($pdodbobj->query($joinedPages,$condition));
    
    ?>
    <div class="clearfix"></div>  

    </div>

    <div class="clearfix"></div>

    <!--=================Header end=======================-->

    <!--=================Body Contain Start=======================-->

    <div class="wrapper">

      <div class="header">

        <?php include_once("dna_top.php"); ?>

 <table width="100%">

 	<tr>

		<td style="vertical-align: top;">
			<div class="new_box_heading" >

				Books

			</div>
		<?php
			if(count($joinedPagesInfo)>0)
			{
		?>
			<table width="90%" border="0" class="under_box">
				<tr>
			<?php
				for($i=0;$i<count($joinedPagesInfo);$i++)
				{
					if($i%2==0 && $i!=0)
					{
					?>
						</tr><tr>
					<?php	
					}
			?>
				
					<td><a style="font-style:inherit;color: inherit;" href="page.php?page=<?php echo $joinedPagesInfo[$i]['Page_Slug']; ?>"><?php echo $joinedPagesInfo[$i]['Comp_Page_Name']; ?></a> </td>
				</tr>
			<?php	
				}
			?>
				</tr>
			</table>
		<?php		
			}
			else
			{
				echo "There is no books.";
			}
		?>
		</td>

		<td style="vertical-align: top;">
        <form name="eventform" method="post" action="dna_events.php?t=<?php echo $_REQUEST['t']; ?>">
        	<div class="new_box_heading">

				Event

			</div>
        <?php
        if(count($eventsinfo)>0)
        {
        ?>
        
        
                <?php
                
                for($i=0;$i<count($eventsinfo);$i++)
                {
                                                   
                    ?>
                    <table width="90%" border="0" class="under_box">
        
        				<tr>
        
        					<td>
                                <div  class="">
                                <span style="text-align:left; float:left; margin-left:20px;">
                                    <a href="javascript:void(0);" onclick="return viewEventInfo('<?php echo base64_encode($eventsinfo[$i]['Event_ID']); ?>',<?php if($_SESSION['Allyfolio_User_ID']==$eventsinfo[$i]['Created_By']){ echo "1"; }else{ echo "0"; } ?>)">
                                        <?php echo $eventsinfo[$i]['Event_Name']; ?>
                                    </a>
                                </span>
                                <?php if($_SESSION['Allyfolio_User_ID']==$eventsinfo[$i]['Created_By']){ 
                                    ?>
                                <span style="position: relative;float: right;margin-right:5px;font-size:14px;color: red;">
                                <a href="javascript:void(0);" onclick="return changeEvent(<?php echo $eventsinfo[$i]['Event_ID']; ?>);">X</a>
                                </span>
                                <?php
                                }
                                ?>
                                <br />
                                <p class="mediumtxt" style="text-align:left; float:left; margin-left:20px;"><?php
                                echo "At : ".$eventsinfo[$i]['Event_Place'];
                                if($eventsinfo[$i]['Event_Date']>0)
                                    echo "   On : ".date("jS, M Y h:i:s A",$eventsinfo[$i]['Event_Date']);
                                ?>
                                </p>
                                </div>
                            </td>
        				</tr>
        
        			</table>
                    
                    <?php
                    
                }
                ?>
       
        <?php
        }
        else
        {
			echo "There is no events";
		}
        ?>
        
            <input type="hidden" id="actiontype" name="actiontype" />
            <input type="hidden" name="event_id" id="event_id"  />
         </form>
		</td>

	</tr>

 </table>
 

       </div>  
       
</div>

    </div>

    

    <div class="clearfix"></div>

    <!--=================Body Contain end=======================-->

    </div>

 <?php
    require_once("includes/footer.php");
?>
<script lang="javascript">
//<![CDATA[

    function viewEventInfo(evtid,flag)
    {
        document.getElementById(['event_id']).value=evtid;
        if(evtid!="")
        {
            if(flag==0)
            {
                document.eventform.action='event_details.php';
                document.getElementById('actiontype').value="";
            }
            else
            {
                document.getElementById('actiontype').value="editeventinfo";    
            }
            
            document.eventform.submit();
        }
    }
    
    function changeEvent(eventid)
    {
        if(eventid>0)
        {
            alertify.confirm("Are you sure, you want to delete Event?", function (e) {
        		if (e) {
        			alertify.success("You've clicked OK");
        			$.ajax({
                      cache:false,  
                      async:false,
                      url: "ajax_search/ajax_manageRequests.php?action=deleteEvent&eventid="+eventid,
                	  success: function( data ) {
                	    if(trim(data)=="success")
                        {
                            alertify.alert("You have successfully delete event.");
                            if(document.getElementById('alertify-cover'))
                            {
                                document.getElementById('alertify-cover').style.display='none';
                            }
                            document.eventform.action='dna_events.php?t=<?php echo $_REQUEST['t']; ?>';
                            document.eventform.submit();
                        }
                        
                	  }
                	});
        		} else {
        			alertify.error("You've clicked Cancel");
        		}
        	});
         }
    }
    
//]]>
</script>